package com.zte.purchase.control;

import com.zte.purchase.model.CFirm;
import com.zte.purchase.model.FirmCondition;
import com.zte.purchase.server.IFirmServer;
import com.zte.util.OperatorLog;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class FirmAction {

    @Autowired
    private IFirmServer firmServer;

    @RequestMapping("/manufacturer/addProductFirm")
//    @OperatorLog(operate="添加厂商", module="采购管理")
    @ResponseBody
    public ResultMessage addProductFirm(CFirm addFirm){
        boolean isAdd = firmServer.addProductFirm(addFirm);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(isAdd);

        return msg;
    }

    @RequestMapping("/manufacturer/updateProductFirm")
//    @OperatorLog(operate="修改厂商", module="采购管理")
    @ResponseBody
    public ResultMessage updateProductFirm(CFirm firm){
        boolean isUpdate = firmServer.updateProductFirm(firm);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(isUpdate);

        return msg;
    }

    @RequestMapping("/manufacturer/findOneFirm")
    @ResponseBody
    public ResultMessage findOneFirm(String firmId){
        CFirm firm = firmServer.findOneFirm(firmId);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(firm);

        return msg;
    }

    @RequestMapping("/manufacturer/queryFirmPage")
//    @OperatorLog(operate="多添加分页查询厂商", module="采购管理")
    @ResponseBody
    public ResultMessage queryFirmPage(Integer pageNum, Integer pageSize, FirmCondition cfConn){
        PageModel<CFirm> model = new PageModel<>();
        model.setPageNum(pageNum);
        model.setPageSize(pageSize);

        PageModel<CFirm> pageModel = firmServer.queryFirmList(model, cfConn);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(pageModel);

        return msg;
    }

}
